# _*_ encoding:utf-8 _*_

"""
    启动静态服务器 + celery服务

    celery:
        -P eventlet -c 10 -----> windows终端下只能使用协程方式运行，否则不会执行消息队列中的函数
"""

# import subprocess
import multiprocessing
import os

path = os.path.dirname(os.path.abspath(__file__))


def static_http_server(ord_path):
    new_path = os.path.join(ord_path, 'front_end_pc')
    os.chdir(new_path)
    os.system('python3 -m http.server 8080')


def celery_server(ord_path):
    new_path = os.path.join(ord_path, 'ihome')
    os.chdir(new_path)
    os.system(
        '/home/ubuntu/.virtualenvs/ihome/bin/celery -A celery_tasks.main worker -l info --concurrency=2 -P eventlet -c 20')


if __name__ == '__main__':
    servers = [static_http_server, celery_server]

    for func in servers:
        server_pr = multiprocessing.Process(target=func, args=(path,))
        server_pr.start()
